package com.example.springbootstudy03jsp.repository.impl;

import com.example.springbootstudy03jsp.bean.User;
import com.example.springbootstudy03jsp.repository.UserDao;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class UserDaoImpl implements UserDao {
    private static Map<Integer,User> map;
    static {
        map=new HashMap<>();
        map.put(1,new User(1,"装三"));
        map.put(2,new User(2,"里斯"));
        map.put(3,new User(3,"汪芜"));
    }
    @Override
    public Collection<User> findAll() {
        return map.values();
    }

    @Override
    public User findById(Integer id) {
        return map.get(id);
    }

    @Override
    public void save(User user) {
        map.put(user.getId(),user);
    }

    @Override
    public void update(User user) {
        map.put(user.getId(),user);
    }

    @Override
    public void delect(Integer id) {
        map.remove(id);
    }
}
